#ifndef __ORAYTYPE_H__
#define __ORAYTYPE_H__

#ifndef WIN32
   #include <sys/time.h>
   #include <sys/uio.h>
   #include <pthread.h>
#else
#pragma warning(disable:4786)
#pragma warning(disable:4146)
	#ifndef WIN32_LEAN_AND_MEAN
	#define WIN32_LEAN_AND_MEAN
	#endif
   #include <Windows.h>
#endif
#include <cstdlib>

#ifndef WIN32
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#else

#endif //WIN32

#ifndef WIN32

#ifndef stricmp
#define stricmp strcasecmp
#endif

#ifndef SOCKET_ERROR
#define SOCKET_ERROR -1
#endif

#ifndef WSAGetLastError
#define WSAGetLastError() errno
#endif

#endif //WIN32

#ifndef WIN32
#define __CLRCALL_OR_CDECL
#define __cdecl
#define __stdcall
#endif //WIN32

#ifndef ARRAY_SIZE
#define ARRAY_SIZE( array )  ( sizeof( array ) / sizeof( array[0] ))
#endif

#ifdef WIN32

typedef unsigned __int64    UINT64;
typedef __int64             INT64;

#else

typedef uint64_t			UINT64;
typedef int64_t             INT64;
typedef int64_t             LONGLONG;
typedef long                LONG;
typedef short               SHORT;
#ifdef __FIX_ULONG__
typedef unsigned long       ULONG_PTR, *PULONG_PTR;
#else
typedef unsigned long       ULONG,ULONG_PTR, *PULONG_PTR;
#endif
typedef char *				LPSTR;
typedef const char *		LPCSTR;

#ifndef	MAX_PATH
#define MAX_PATH 260
#endif

#ifndef FALSE
#define FALSE 0
#endif // !FALSE

#ifndef TRUE 
#define TRUE 1
#endif // !TRUE




#ifndef BYTE_DEFINED
#define BYTE_DEFINED
typedef unsigned char BYTE;
#endif // !_BYTE_DEFINED

#ifndef WORD_DEFINED
#define WORD_DEFINED
typedef unsigned short WORD;
#endif // !_WORD_DEFINED

typedef unsigned int UINT;
typedef int INT;

#ifdef __APPLE__
#include <objc/objc.h>
#else
typedef int BOOL;
#endif //__APPLE__

#ifndef LONG_DEFINED
#define LONG_DEFINED
typedef long LONG;
#endif // LONG_DEFINED

#ifndef DWORD_DEFINED
#define DWORD_DEFINED
typedef uint32_t DWORD;
#endif //DWORD_DEFINED

#endif //WIN32

#ifndef ULONGLONG_DEFINED
#define ULONGLONG_DEFINED
typedef UINT64 ULONGLONG;
#endif //ULONGLONG_DEFINED

#if !defined(WIN32) && !defined(__ANDROID__)

#ifndef NO_ERROR
#define NO_ERROR 0
#endif //NO_ERROR

#endif //!defined(WIN32) && !defined(__ANDROID__)

typedef unsigned int        UINT32;
typedef unsigned short      UINT16;
typedef unsigned char       UINT8;
typedef int                 INT32;
typedef short               INT16;


// Start modified by Cao Yangmin @ 2008-6-10 for 
/* */ 
//typedef char                INT8;
//������<basetsd.h>��ͻ
// End modified by Cao Yangmin @ 2008-6-10 for 
typedef signed char         INT8;


////////////////////////////
// Variable size
//		These will always be at least as big as the largest
//		fixed-size data-type

typedef UINT32              OUINT;
typedef INT32               OINT;


////////////////////////////
// Boolean

typedef int OBOOL;
const OBOOL OTRUE  = -1;
const OBOOL OFALSE = 0;

////////////////////////////
// Others

typedef char OChar;

#if (!defined(NULL))
#define NULL 0
#endif

////////////////////////////

typedef OChar * OString;
typedef UINT32  OERR;

#ifndef WIN32
typedef const void			*LPCVOID;
typedef void				*PVOID;
typedef void				*LPVOID;
typedef PVOID				HANDLE;

#ifndef HWND_DEFINED
#define HWND_DEFINED
typedef HANDLE				HWND;
#endif

typedef HANDLE				HDC;
typedef HANDLE				HICON;
typedef HICON				HCURSOR;

#if defined(_WIN64)
typedef unsigned __int64    UINT_PTR;
typedef __int64 			LONG_PTR; 
#elif __x86_64__ /**64位linux下用到  */
typedef uint64_t            UINT_PTR;
typedef int64_t 			LONG_PTR; 
#elif __aarch64__
typedef uint64_t            UINT_PTR;
typedef int64_t 			LONG_PTR; 
#else
typedef unsigned int        UINT_PTR;
typedef long 				LONG_PTR;
#endif

typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;

typedef struct tagPOINT {
	tagPOINT()
		:x(0)
		,y(0)
	{
	}

	tagPOINT(const tagPOINT &point)
		:x(point.x)
		,y(point.y)
	{
	}

	tagPOINT( long px, long py)
		:x(px)
		,y(py)
	{
	}

	tagPOINT& operator+(const tagPOINT& point) 
	{
		x += point.x;
		y += point.y;
		return *this;
	}

	tagPOINT& operator-(const tagPOINT& point) 
	{
		x -= point.x;
		y -= point.y;
		return *this;
	}

	tagPOINT& operator=(const tagPOINT& point) 
	{
		x = point.x;
		y = point.y;
		return *this;
	}

    int32_t x;
    int32_t y;
} POINT; 

typedef struct tagSIZE
{
	int32_t cx;
	int32_t cy;
} SIZE;

#endif


/** \brief Size define with cross platform 
 * \@warnning this type is not OrayUI::SIZEF
 */
typedef struct tagSIZEF {
	double cx;
	double cy;
} SIZEF2;

#ifndef WIN32
/*
 * WinSock 2 extension -- WSABUF and QOS struct, include qos.h
 * to pull in FLOWSPEC and related definitions
 */
 #ifndef SOCKADDR_IN
 #define SOCKADDR_IN sockaddr_in
 #endif
 
 
#ifndef SOCKET
#define SOCKET int32_t
#endif

typedef struct _OVERLAPPED {
    ULONG_PTR Internal;
    ULONG_PTR InternalHigh;
    union {
        struct {
            DWORD Offset;
            DWORD OffsetHigh;
        };

        PVOID Pointer;
    };

    HANDLE  hEvent;
} OVERLAPPED, *LPOVERLAPPED;


typedef struct _WSABUF {
    unsigned long len;     /* the length of the buffer */
    char *buf; /* the pointer to the buffer */
} WSABUF, * LPWSABUF;

#endif //WIN32

// 跨平台的类型定义
// 解决不同编译平台之间的类型无法识别的问题
// compatible types

#ifndef WIN32

#ifndef RECT_DEFINED
#define RECT_DEFINED
typedef struct tagRECT 
{
	int32_t left;
	int32_t top;
	int32_t right;
	int32_t bottom;

	void set(int32_t l, int32_t t, int32_t r, int32_t b) 
	{
		left = l;
		top = t;
		right = r;
		bottom = b;
	}

	int32_t width() const { return right - left; }
	int32_t height() const { return bottom - top; }
} RECT, *PRECT, *LPRECT;
typedef const RECT  *LPCRECT;

static inline
bool SetRect(LPRECT lprc, int32_t xLeft, int32_t yTop, int32_t xRight, int32_t yBottom)
{
    if(lprc == NULL) return false;
    lprc->left = xLeft;
    lprc->top = yTop;
    lprc->right = xRight;
    lprc->bottom = yBottom;
    return true;
}

#endif //RECT_DEFINED

#endif


/*******************************************************************************
**
**  4. EXPORTED DATA / GROBAL FUNCTION PROTOTYPES
**
*******************************************************************************/

/*******************************************************************************
**
**  5. FUNCTION PROTOTYPES (file scope only)
**
*******************************************************************************/

/*******************************************************************************
**
**  6. CLASS DECLARATIONS
**
*******************************************************************************/


#endif //__ORAYTYPE_H__
